import { EnumBjlResult } from "../enums/EnumBjlResult";
import { RoundInfo } from "./ExecutePlan";

/**
 * 推荐策略
 */
export interface IRecmStrategy {
    /**
     * 设置配置参数
     * @param option 配置参数
     */
    setOption<T>(option: T): void;
    /**
     * 获取推荐
     * @param roundInfo 当前轮信息
     */
    toResult(roundInfo: RoundInfo): EnumBjlResult;
}

export interface IFollowOption {
    followCount: number;
}
/**
 * 跟投策略
 */
export class FollowStrategy implements IRecmStrategy {
    /**
     * 配置
     */
    option: IFollowOption;
    /**
     * 构造函数
     */
    constructor() {
        this.option = { followCount: 1 };
    }
    /**
     * 设置参数配置
     * @param option 参数配置
     */
    setOption<T>(option: T): void {
        this.option = option as IFollowOption;
        if(!this.option) throw new Error("【跟投策略】参数不正确");
    }
    toResult(roundInfo: RoundInfo): EnumBjlResult {
        let count = roundInfo.Results.length;
        let result = EnumBjlResult.U;
        if (count >= this.option.followCount) {
            result = roundInfo.Results[count - this.option.followCount];
        }
        return result;
    }

}

export interface IArrayOption {
    betArray:Array<EnumBjlResult>;
}
/**
 * 固定图形策略
 */
export class ArrayStrategy implements IRecmStrategy {
    /**
     * 配置
     */
    option: IArrayOption;
    /**
     * 构造函数
     */
    constructor() {
        this.option = { betArray :[] };
    }

    setOption(option: any): void {
        this.option = option as IArrayOption;
        if(!this.option) throw new Error("【固定图形策略】参数不正确");
    }
    toResult(roundInfo: RoundInfo): EnumBjlResult {
        let count = roundInfo.Results.length;
        let index = count % this.option.betArray.length;
        return index >=0? this.option.betArray[index]:EnumBjlResult.U;
    }

}
/**
 * 
 */
export interface IRandomNumOption{
    num:number;
}
/**
 * 
 */
export class RandomNumStrategy implements IRecmStrategy{
    /**
     * 配置
     */
    option: IFollowOption;
    /**
     * 构造函数
     */
    constructor() {
        this.option = { followCount: 1 };
    }
    setOption<T>(option: T): void {
        throw new Error("Method not implemented.");
    }
    toResult(roundInfo: RoundInfo): EnumBjlResult {
        throw new Error("Method not implemented.");
    }
    
}